/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package model;

import xmlaufgabe7.ContentParser;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Observable;
import org.xml.sax.InputSource;
import xmlaufgabe7.SAXParser;
import xmlaufgabe7.UebungData;

/**
 *
 * @author s0527676
 */
public class LoaderModel extends Observable {
    private InputSource input;
    private ArrayList<UebungData> modelList;
    private SAXParser saxParser;

    public LoaderModel() throws MalformedURLException, IOException {
        URL url = new URL("http://harald-brandenburg.de/xml-jaxp/xml-jaxp.xml");
        URLConnection connection = url.openConnection();
        connection.setRequestProperty("User-Agent", "Adrian Cieluch s0527676");
        input = new InputSource(connection.getInputStream());
        modelList = new ArrayList<UebungData>();
        
        ContentParser contentParser = new ContentParser(modelList);
        saxParser = new SAXParser(input, contentParser);
    }
    
    public void loadData() {
        saxParser.parseXMLDocument(false, true);
        this.setChanged();
        this.notifyObservers(modelList);
    }
    
    public ArrayList<UebungData> getDataModelList() {
        return modelList;
    }
}
